from django.db import models



class Recruiter(models.Model):
    """招聘者个人信息表"""
    username = models.CharField(max_length=50, unique=True, verbose_name="登录账号")
    password = models.CharField(max_length=128, verbose_name="加密密码")
    name = models.CharField(max_length=50, blank=True, null=True, verbose_name="姓名")  # 个人信息页面填写
    avatar = models.URLField(blank=True, null=True, verbose_name="头像URL")  # 头像上传后存储URL
    position = models.CharField(max_length=100, blank=True, null=True, verbose_name="公司职务")  # 个人信息页面填写
    is_complete = models.BooleanField(default=False, verbose_name="信息是否完善")  # 判断是否首次登录
    # created_at = models.DateTimeField(auto_now_add=True)
    ext_1 = models.CharField(null=True, blank=True, max_length=250, verbose_name='扩展字段1')
    ext_2 = models.CharField(null=True, blank=True, max_length=250, verbose_name='扩展字段2')
    ext_3 = models.CharField(null=True, blank=True, max_length=250, verbose_name='扩展字段3')

    class Meta:
        verbose_name = "招聘者"
        verbose_name_plural = "招聘者"
        db_table = 'recruiter'

# Create your models here.


class CCompany(models.Model):
    COMPANY_SCALE = (
        ('1-50', '1-50人'),
        ('50-100', '50-100人'),
        ('100-500', '100-500人'),
        ('500-1000', '500-1000人'),
        ('1000+', '1000人以上'),
    )
    INDUSTRY_CHOICES = (
        ('internet', '互联网'),
        ('finance', '金融'),
        ('education', '教育'),
        ('healthcare', '医疗'),
        ('manufacturing', '制造业'),
        ('real_estate', '房地产'),
        ('other', '其他'),
    )
    name = models.CharField(max_length=100, verbose_name='公司全称')
    short_name = models.CharField(max_length=20, verbose_name='公司简称')
    logo = models.URLField(null=True, blank=True, verbose_name='公司Logo URL')
    scale = models.CharField(max_length=20, choices=COMPANY_SCALE, verbose_name='公司规模')
    description = models.TextField(verbose_name='公司描述')
    address = models.CharField(max_length=200, verbose_name='公司地址')
    industry = models.CharField(max_length=20, choices=INDUSTRY_CHOICES, verbose_name='所属行业')
    is_verified = models.BooleanField(default=False, verbose_name='是否认证')
    # created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    business_license = models.CharField(null=True, blank=True,max_length=250, verbose_name='营业执照号')
    license_image = models.URLField(null=True, blank=True, verbose_name='营业执照图片URL')
    recruiter = models.ForeignKey(Recruiter, on_delete=models.CASCADE, related_name='companies')
    ext_1 = models.CharField(null=True, blank=True, max_length=250, verbose_name='扩展字段1')
    ext_2 = models.CharField(null=True, blank=True, max_length=250, verbose_name='扩展字段2')
    ext_3 = models.CharField(null=True, blank=True, max_length=250, verbose_name='扩展字段3')
    class Meta:
        db_table = 'ccompany'


class Job(models.Model):
    JOB_TYPE = (
        ('full_time', '全职'),
        ('part_time', '兼职'),
        ('internship', '实习'),
        ('contract', '合同制'),
    )

    SALARY_RANGE = (
        ('3k以下', '3k以下'),
        ('3-5k', '3-5k'),
        ('5-10k', '5-10k'),
        ('10-15k', '10-15k'),
        ('15-20k', '15-20k'),
        ('20-30k', '20-30k'),
        ('30-50k', '30-50k'),
        ('50k以上', '50k以上'),
    )

    EDUCATION_REQUIREMENT = (
        ('none', '不限'),
        ('high_school', '高中'),
        ('college', '大专'),
        ('bachelor', '本科'),
        ('master', '硕士'),
        ('doctor', '博士'),
    )

    EXPERIENCE_REQUIREMENT = (
        ('none', '不限'),
        ('fresh', '应届生'),
        ('1-3', '1-3年'),
        ('3-5', '3-5年'),
        ('5-10', '5-10年'),
        ('10+', '10年以上'),
    )

    JOB_STATUS = (
        ('published', '已发布'),
        ('closed', '已关闭'),
        ('expired', '已过期'),
    )

    # 基础信息
    title = models.CharField(max_length=100, verbose_name='岗位标题')
    company = models.ForeignKey(CCompany, on_delete=models.CASCADE, verbose_name='所属企业')
    publisher = models.ForeignKey(Recruiter, on_delete=models.CASCADE, verbose_name='发布者')

    # 岗位详情
    job_type = models.CharField(max_length=20, choices=JOB_TYPE, verbose_name='工作类型')

    # 薪资待遇
    salary_range = models.CharField(max_length=20, choices=SALARY_RANGE, verbose_name='薪资范围')

    # 要求信息
    education_requirement = models.CharField(max_length=20, choices=EDUCATION_REQUIREMENT, default='none',
                                             verbose_name='学历要求')
    experience_requirement = models.CharField(max_length=20, choices=EXPERIENCE_REQUIREMENT, default='none',
                                              verbose_name='经验要求')

    # 工作地点
    work_city = models.CharField(max_length=50, verbose_name='工作城市')

    # 岗位描述
    description = models.TextField(verbose_name='岗位描述')
    requirements = models.TextField(verbose_name='任职要求')
    benefits = models.TextField(blank=True, verbose_name='福利待遇')

    # 招聘信息
    vacancy_count = models.IntegerField(default=1, verbose_name='招聘人数')

    # 状态管理
    status = models.CharField(max_length=10, choices=JOB_STATUS, default='draft', verbose_name='岗位状态')
    published_at = models.DateTimeField(null=True, blank=True, verbose_name='发布时间')
    expired_at = models.DateTimeField(verbose_name='过期时间')

    # 统计信息
    view_count = models.IntegerField(default=0, verbose_name='浏览数')
    apply_count = models.IntegerField(default=0, verbose_name='申请数')

    # 地理位置
    longitude = models.DecimalField(max_digits=10, decimal_places=6, verbose_name="经度")  # 核心字段
    latitude = models.DecimalField(max_digits=10, decimal_places=6, verbose_name="纬度")  # 核心字段

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        verbose_name = '招聘岗位'
        verbose_name_plural = '招聘岗位'
        db_table = 'job'












